<?php
/**
 * Created by PhpStorm.
 * User: h
 * Date: 2021/4/8
 * Time: 16:05
 */

namespace app\api\controller\v1;

use app\common\model\Student as StudentModel;
use app\common\model\Banner as BannerModel;

class Student extends BaseController
{
    public function index()
    {
        return sucessMsg(200, '获取成功', [
            'banner' => $this->banner(),//获取banner图
            'getinfo' => $this->getinfo()//获取个人信息
        ]);
    }

    public function banner()
    {
        $model = new BannerModel();
        $banner = $model->where('type', 5)
            ->where('status', 1)
            ->field('image')
            ->order('sort', 'asc')
            ->select();
        foreach ($banner as $v) {
            $v['image'] = config("app.domain_url") . str_replace('\\', '/', $v['image']);
        }
        return $banner;
    }

    public function getinfo()
    {
        $id = input('id/d');
        $model = new StudentModel();
        $student = $model->where('status', 1)
            ->where('id', $id)
            ->field('id,image,number,name,phone,school_id,major_id')
            ->find();
        $student['image'] = config("app.domain_url") . str_replace('\\', '/', $student['image']);
        $student['school_id'] = $student->school->name;
        $student['major_id'] = $student->major->name;
        //销毁变量
        unset($student->school);
        unset($student->major);

        return $student;
    }
}